using Exam.Domain.Tables;
using Exam.IRepositoy;
using Exam.IService;
using Exam.Repositoy;
using Exam.Service;
using Microsoft.EntityFrameworkCore;


var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();

AutoMapper.IConfigurationProvider configurationProvider = new AutoMapper.MapperConfiguration(cnf =>
 {
     cnf.AddProfile<Exam.Application.ExamApiMappingProfile>();
 });

builder.Services.AddSingleton(configurationProvider);
builder.Services.AddScoped<AutoMapper.IMapper, AutoMapper.Mapper>();
builder.Services.AddScoped<IProductCategoryService, ProductCategoryService>();

builder.Services.AddScoped<IBaseRepository<Tb_Proudct_Category>, BaseRepository<Tb_Proudct_Category>>();
//
builder.Services.AddScoped<IProductCategoryRepository, ProductCategoryRepository>();

builder.Services.AddSwaggerGen();

builder.Services.AddDbContext<Exam.EntityFramework.ExamDbContext>(opt => {

    var conn = builder.Configuration.GetConnectionString("MainConnectionString");
    opt.UseMySql(conn, ServerVersion.AutoDetect(conn));

});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
